<div class="row main-content">
	<div class="col-sm-2">
		<div class="box box-skin">
			<div class="box-body no-padding">
				<table class="table table-hover treetable"></table>
			</div>
		</div>
	</div>
	<div class="col-sm-10 p-l-15-0">
		<div class="box box-skin">
			<div class="box-body no-padding">
			    <div id="toolbar">
					<div class="form-inline" role="form">
				    	<div class="form-group btn-group">
		                    <button type="button" class="btn btn-default btn-flat" onclick="CRUDContentFunc(1);" title="添加"><i class="fa fa-plus"></i></button>
		                    <button type="button" class="btn btn-default btn-flat" onclick="CRUDContentFunc(5);" title="批量删除"><i class="fa fa-trash"></i></button>
		                </div>
		                <!-- <div class="form-group">
		                    <input type="text" class="form-control" name="likeMap[name]" placeholder="名称" />
		                </div>
		                <div class="form-group">
		                    <input type="text" class="form-control" name="likeMap[table_name]" placeholder="表名" />
		                </div> -->
				    	<div class="form-group btn-group">
		                	<!-- <button type="button" class="btn btn-default btn-flat" onclick="searchFunc();" title="搜索"><i class="fa fa-search"></i></button> -->
		                	<button type="button" class="btn btn-default btn-flat" onclick="reloadFunc();" title="重新加载"><i class="fa fa-refresh"></i></button>
		            	</div>
		            </div>
			    </div>
				<table id="table"></table>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript" src="__TMPL__Public/pages/setting/content.js"></script>
<script type="text/javascript">
$(function() {
	/* xtreetable */
	var columns = [{
        title: '分类',
        field: 'name',
        formatter: function(value, row, index) {
			var str = '';
			str += '<a href="javascript:;" class="" onclick="loadContentByContentCatIdFunc(' + row.id + ');">' + value + '</a>';
			return str;
		},
    }];
	xtt = xtreetable('.treetable', {
		url: "{:U('Setting/ContentCat/getAll')}",
		columns: columns,
		ajaxDataFilter: function(data) {
			return data.obj;
        },
	});
	
	$('#table').bootstrapTable({
		classes: 'table table-no-bordered table-hover',
		striped: true,
		toolbar: '#toolbar',
		showColumns: true,
	    showPaginationSwitch: true,
	    pagination: true,
		sidePagination: 'server',
		pageSize: 10,
		pageList: '[10, 15, 50, 100, All]',
		queryParams: queryParams,
		queryParamsType: 'limit',
		sortName: 'id',
		sortOrder: 'desc',
		url: "{:U('Setting/Content/dataListByContentCatId')}?cid=0",
	    idField: 'id',
	    columns: [{
            field: 'state',
            checkbox: true,
            visible: false,
//			width: '20%',
            align: 'left',
            valign: 'middle',
        }, {
	        title: 'ID',
	        field: 'id',
	        sortable: true,
            visible: false,
//			width: '20%',
            align: 'left',
            valign: 'middle',
	    }, {
	        title: '标题',
	        field: 'title',
	        sortable: true,
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
    			return '<span class="x-ellipsis with-w-200">' + value + '</span>';
    		},
	    }, {
	        title: '分类',
	        field: 'cname',
	        sortable: true,
//			width: '20%',
            align: 'left',
            valign: 'middle',
	    }, {
	        title: '简介',
	        field: 'summary',
	        sortable: true,
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
    			return '<span class="x-ellipsis with-w-200">' + value + '</span>';
    		},
	    }, {
	        title: '链接地址',
	        field: 'url',
	        sortable: true,
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
    			return '<span class="x-ellipsis with-w-200">' + value + '</span>';
    		},
	    }, {
	        title: '状态',
	        field: 'status',
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
            	var str = '';
            	if (value == 0) {
            		str = '<span class="label label-warning">保留</span>';
            	} else if (value == 1) {
            		str = '<span class="label label-success">已启用</span>';
            	} else if (value == -1) {
            		str = '<span class="label label-default">已删除</span>';
            	} else if (value == -2) {
            		str = '<span class="label label-default">已禁用</span>';
            	}
    			return str;
    		},
	    }, {
            title: '操作',
            field: 'operate',
//			width: '20%',
            align: 'left',
            valign: 'middle',
            formatter: function(value, row, index) {
				var str = '';
				str += '<div class="btn-group">';
				str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="CRUDContentFunc(2, ' + row.id + ');">查看</button>';
				str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="CRUDContentFunc(3, ' + row.id + ', ' + index + ');">编辑</button>';
				str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="forbiddenContentFunc('+ row.id + ', ' + index + ');">禁用</button>';
				str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="CRUDContentFunc(4, ' + row.id + ');">删除</button>';
				str += '</div>';
				return str;
			},
        }],
	});
});

/* loadContentByContentCatIdFunc */
function loadContentByContentCatIdFunc(contentCatId) {
	var url = "{:U('Setting/Content/dataListByContentCatId')}?cid=" + contentCatId;
	$('#toolbar').resetForm();
	$('#table').bootstrapTable('refresh', {url: url});
}

/* search */
function queryParams(params) {
    $('#toolbar').find('input[name], select[name]').each(function () {
        params[$(this).attr('name')] = $(this).val();
    });
    return params;
}

function searchFunc() {
	$('#table').bootstrapTable('selectPage', 1);			// IMPORTANT!!!  有刷新功能!!!
}

/* reload */
function reloadFunc() {
	$('#toolbar').resetForm();
	$('#table').bootstrapTable('selectPage', 1);
}
</script>
